from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2021-01-11 14:19:18.709651
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Mon, 11, Jan, 2021
Time: 14:19:23
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -44.9358
Nobs: 168.000 HQIC: -45.9301
Log likelihood: 1859.75 FPE: 5.73290e-21
AIC: -46.6093 Det(Omega_mle): 3.40705e-21
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.465594 0.152180 3.059 0.002
L1.Burgenland 0.138657 0.077917 1.780 0.075
L1.Kärnten -0.239278 0.063213 -3.785 0.000
L1.Niederösterreich 0.118791 0.180951 0.656 0.512
L1.Oberösterreich 0.234202 0.154852 1.512 0.130
L1.Salzburg 0.188343 0.081802 2.302 0.021
L1.Steiermark 0.078094 0.111919 0.698 0.485
L1.Tirol 0.150673 0.074110 2.033 0.042
L1.Vorarlberg 0.008738 0.070972 0.123 0.902
L1.Wien -0.127684 0.150448 -0.849 0.396
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.537172 0.195545 2.747 0.006
L1.Burgenland 0.012521 0.100120 0.125 0.900
L1.Kärnten 0.369008 0.081226 4.543 0.000
L1.Niederösterreich 0.121849 0.232514 0.524 0.600
L1.Oberösterreich -0.181096 0.198978 -0.910 0.363
L1.Salzburg 0.178361 0.105112 1.697 0.090
L1.Steiermark 0.241275 0.143811 1.678 0.093
L1.Tirol 0.143521 0.095228 1.507 0.132
L1.Vorarlberg 0.185103 0.091196 2.030 0.042
L1.Wien -0.591973 0.193319 -3.062 0.002
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.300812 0.067447 4.460 0.000
L1.Burgenland 0.106310 0.034533 3.078 0.002
L1.Kärnten -0.024061 0.028017 -0.859 0.390
L1.Niederösterreich 0.064115 0.080199 0.799 0.424
L1.Oberösterreich 0.284718 0.068632 4.148 0.000
L1.Salzburg -0.001116 0.036255 -0.031 0.975
L1.Steiermark -0.022905 0.049603 -0.462 0.644
L1.Tirol 0.097519 0.032846 2.969 0.003
L1.Vorarlberg 0.127338 0.031455 4.048 0.000
L1.Wien 0.073357 0.066680 1.100 0.271
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.214413 0.079389 2.701 0.007
L1.Burgenland -0.005970 0.040648 -0.147 0.883
L1.Kärnten 0.023313 0.032977 0.707 0.480
L1.Niederösterreich 0.030265 0.094398 0.321 0.749
L1.Oberösterreich 0.391944 0.080783 4.852 0.000
L1.Salzburg 0.093669 0.042674 2.195 0.028
L1.Steiermark 0.180773 0.058385 3.096 0.002
L1.Tirol 0.041540 0.038661 1.074 0.283
L1.Vorarlberg 0.100214 0.037024 2.707 0.007
L1.Wien -0.071990 0.078485 -0.917 0.359
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.577709 0.158396 3.647 0.000
L1.Burgenland 0.078239 0.081100 0.965 0.335
L1.Kärnten 0.002241 0.065795 0.034 0.973
L1.Niederösterreich -0.027013 0.188342 -0.143 0.886
L1.Oberösterreich 0.138730 0.161177 0.861 0.389
L1.Salzburg 0.049728 0.085143 0.584 0.559
L1.Steiermark 0.108694 0.116490 0.933 0.351
L1.Tirol 0.220109 0.077137 2.853 0.004
L1.Vorarlberg 0.013023 0.073871 0.176 0.860
L1.Wien -0.145495 0.156593 -0.929 0.353
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.171319 0.112453 1.523 0.128
L1.Burgenland -0.022864 0.057576 -0.397 0.691
L1.Kärnten -0.013147 0.046711 -0.281 0.778
L1.Niederösterreich 0.174140 0.133713 1.302 0.193
L1.Oberösterreich 0.379447 0.114427 3.316 0.001
L1.Salzburg -0.033210 0.060447 -0.549 0.583
L1.Steiermark -0.048461 0.082702 -0.586 0.558
L1.Tirol 0.195830 0.054763 3.576 0.000
L1.Vorarlberg 0.046796 0.052444 0.892 0.372
L1.Wien 0.158225 0.111173 1.423 0.155
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.236398 0.141553 1.670 0.095
L1.Burgenland 0.062386 0.072476 0.861 0.389
L1.Kärnten -0.048054 0.058799 -0.817 0.414
L1.Niederösterreich -0.038230 0.168314 -0.227 0.820
L1.Oberösterreich -0.102531 0.144038 -0.712 0.477
L1.Salzburg 0.024916 0.076089 0.327 0.743
L1.Steiermark 0.378135 0.104103 3.632 0.000
L1.Tirol 0.516264 0.068934 7.489 0.000
L1.Vorarlberg 0.188172 0.066016 2.850 0.004
L1.Wien -0.214939 0.139941 -1.536 0.125
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.121012 0.165964 0.729 0.466
L1.Burgenland 0.011650 0.084975 0.137 0.891
L1.Kärnten -0.106712 0.068939 -1.548 0.122
L1.Niederösterreich 0.219152 0.197341 1.111 0.267
L1.Oberösterreich 0.005120 0.168878 0.030 0.976
L1.Salzburg 0.223795 0.089211 2.509 0.012
L1.Steiermark 0.149021 0.122056 1.221 0.222
L1.Tirol 0.095451 0.080822 1.181 0.238
L1.Vorarlberg 0.011533 0.077400 0.149 0.882
L1.Wien 0.279462 0.164075 1.703 0.089
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.592393 0.090353 6.556 0.000
L1.Burgenland -0.021193 0.046261 -0.458 0.647
L1.Kärnten -0.001622 0.037531 -0.043 0.966
L1.Niederösterreich -0.014445 0.107435 -0.134 0.893
L1.Oberösterreich 0.279663 0.091940 3.042 0.002
L1.Salzburg 0.009149 0.048568 0.188 0.851
L1.Steiermark -0.000580 0.066449 -0.009 0.993
L1.Tirol 0.078813 0.044001 1.791 0.073
L1.Vorarlberg 0.170237 0.042138 4.040 0.000
L1.Wien -0.087197 0.089325 -0.976 0.329
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.147213 0.004645 0.211489 0.246449 0.064985 0.099424 -0.071065 0.160089
Kärnten 0.147213 1.000000 0.002060 0.190196 0.153784 -0.131621 0.160611 0.026658 0.304998
Niederösterreich 0.004645 0.002060 1.000000 0.287245 0.087586 0.216024 0.102260 0.065293 0.353034
Oberösterreich 0.211489 0.190196 0.287245 1.000000 0.290095 0.313681 0.094711 0.082894 0.121405
Salzburg 0.246449 0.153784 0.087586 0.290095 1.000000 0.154322 0.076286 0.076823 -0.023590
Steiermark 0.064985 -0.131621 0.216024 0.313681 0.154322 1.000000 0.098362 0.089355 -0.120634
Tirol 0.099424 0.160611 0.102260 0.094711 0.076286 0.098362 1.000000 0.150271 0.134451
Vorarlberg -0.071065 0.026658 0.065293 0.082894 0.076823 0.089355 0.150271 1.000000 0.101251
Wien 0.160089 0.304998 0.353034 0.121405 -0.023590 -0.120634 0.134451 0.101251 1.000000